home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdb / sample.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  12.2 KB  |  416 lines

  1. VERSION 2.00
  2. Begin Form Rollodex 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Sample Address Book"
  5.    ClientHeight    =   4440
  6.    ClientLeft      =   1050
  7.    ClientTop       =   1815
  8.    ClientWidth     =   7560
  9.    Height          =   4845
  10.    Left            =   990
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form2"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   4440
  16.    ScaleWidth      =   7560
  17.    Top             =   1470
  18.    Width           =   7680
  19.    Begin TextBox WorkPhone 
  20.       Height          =   372
  21.       Left            =   1680
  22.       TabIndex        =   9
  23.       Text            =   "(908) 707-1316"
  24.       Top             =   3960
  25.       Width           =   1332
  26.    End
  27.    Begin TextBox HomePhone 
  28.       Height          =   372
  29.       Left            =   1680
  30.       TabIndex        =   8
  31.       Text            =   "(908) 707-1316"
  32.       Top             =   3480
  33.       Width           =   1332
  34.    End
  35.    Begin TextBox ThisRec 
  36.       Height          =   372
  37.       Left            =   6960
  38.       TabIndex        =   23
  39.       Top             =   3036
  40.       Width           =   492
  41.    End
  42.    Begin TextBox Zip 
  43.       Height          =   372
  44.       Left            =   1680
  45.       TabIndex        =   7
  46.       Text            =   "08807"
  47.       Top             =   3000
  48.       Width           =   1092
  49.    End
  50.    Begin TextBox State 
  51.       Height          =   372
  52.       Left            =   1680
  53.       TabIndex        =   6
  54.       Text            =   "NJ"
  55.       Top             =   2520
  56.       Width           =   372
  57.    End
  58.    Begin TextBox City 
  59.       Height          =   372
  60.       Left            =   1680
  61.       TabIndex        =   5
  62.       Text            =   "Bridgewater"
  63.       Top             =   2040
  64.       Width           =   2292
  65.    End
  66.    Begin CommandButton Quit 
  67.       Caption         =   "E&xit"
  68.       Height          =   492
  69.       Left            =   6360
  70.       TabIndex        =   22
  71.       Top             =   1920
  72.       Width           =   1092
  73.    End
  74.    Begin TextBox Address 
  75.       Height          =   372
  76.       Left            =   1680
  77.       TabIndex        =   4
  78.       Text            =   "135 Chestnut Street"
  79.       Top             =   1560
  80.       Width           =   3972
  81.    End
  82.    Begin TextBox Contact 
  83.       Height          =   372
  84.       Left            =   1680
  85.       TabIndex        =   3
  86.       Text            =   "02/06/1961"
  87.       Top             =   1080
  88.       Width           =   1092
  89.    End
  90.    Begin CommandButton New 
  91.       Caption         =   "&New"
  92.       Height          =   492
  93.       Left            =   6360
  94.       TabIndex        =   21
  95.       Top             =   840
  96.       Width           =   1092
  97.    End
  98.    Begin TextBox Lname 
  99.       Height          =   372
  100.       Left            =   1680
  101.       TabIndex        =   2
  102.       Text            =   "Marquis"
  103.       Top             =   600
  104.       Width           =   2052
  105.    End
  106.    Begin CommandButton Save 
  107.       Caption         =   "&Save"
  108.       Height          =   492
  109.       Left            =   6360
  110.       TabIndex        =   20
  111.       Top             =   240
  112.       Width           =   1092
  113.    End
  114.    Begin TextBox Fname 
  115.       Height          =   372
  116.       Left            =   1680
  117.       TabIndex        =   1
  118.       Text            =   "Hank"
  119.       Top             =   120
  120.       Width           =   1092
  121.    End
  122.    Begin VScrollBar Record 
  123.       Height          =   4452
  124.       Left            =   5880
  125.       TabIndex        =   0
  126.       Top             =   0
  127.       Width           =   252
  128.    End
  129.    Begin TextBox Text1 
  130.       BackColor       =   &H00C0C0C0&
  131.       BorderStyle     =   0  'None
  132.       Enabled         =   0   'False
  133.       Height          =   4572
  134.       Left            =   6144
  135.       TabIndex        =   19
  136.       Top             =   -36
  137.       Width           =   1416
  138.    End
  139.    Begin Label Label9 
  140.       Alignment       =   1  'Right Justify
  141.       Caption         =   "&Work phone:"
  142.       Height          =   372
  143.       Left            =   480
  144.       TabIndex        =   18
  145.       Top             =   4080
  146.       Width           =   1092
  147.    End
  148.    Begin Label Label8 
  149.       Alignment       =   1  'Right Justify
  150.       Caption         =   "&Home phone:"
  151.       Height          =   372
  152.       Left            =   120
  153.       TabIndex        =   17
  154.       Top             =   3600
  155.       Width           =   1452
  156.    End
  157.    Begin Label Label7 
  158.       Alignment       =   1  'Right Justify
  159.       Caption         =   "&Zip code:"
  160.       Height          =   372
  161.       Left            =   480
  162.       TabIndex        =   16
  163.       Top             =   3120
  164.       Width           =   1092
  165.    End
  166.    Begin Label Label10 
  167.       Alignment       =   1  'Right Justify
  168.       BackColor       =   &H00C0C0C0&
  169.       Caption         =   "Record no:"
  170.       Height          =   492
  171.       Left            =   6168
  172.       TabIndex        =   24
  173.       Top             =   3000
  174.       Width           =   768
  175.    End
  176.    Begin Label Label6 
  177.       Alignment       =   1  'Right Justify
  178.       Caption         =   "&State:"
  179.       Height          =   372
  180.       Left            =   480
  181.       TabIndex        =   15
  182.       Top             =   2640
  183.       Width           =   1092
  184.    End
  185.    Begin Label Label5 
  186.       Alignment       =   1  'Right Justify
  187.       Caption         =   "&City:"
  188.       Height          =   372
  189.       Left            =   480
  190.       TabIndex        =   14
  191.       Top             =   2160
  192.       Width           =   1092
  193.    End
  194.    Begin Label Label4 
  195.       Alignment       =   1  'Right Justify
  196.       Caption         =   "&Address:"
  197.       Height          =   372
  198.       Left            =   480
  199.       TabIndex        =   13
  200.       Top             =   1680
  201.       Width           =   1092
  202.    End
  203.    Begin Label Label3 
  204.       Alignment       =   1  'Right Justify
  205.       Caption         =   "Last &contact:"
  206.       Height          =   372
  207.       Left            =   480
  208.       TabIndex        =   12
  209.       Top             =   1200
  210.       Width           =   1092
  211.    End
  212.    Begin Label Label2 
  213.       Alignment       =   1  'Right Justify
  214.       Caption         =   "Last &name:"
  215.       Height          =   372
  216.       Left            =   480
  217.       TabIndex        =   11
  218.       Top             =   720
  219.       Width           =   1092
  220.    End
  221.    Begin Label Label1 
  222.       Alignment       =   1  'Right Justify
  223.       Caption         =   "&First name:"
  224.       Height          =   252
  225.       Left            =   480
  226.       TabIndex        =   10
  227.       Top             =   240
  228.       Width           =   1092
  229.    End
  230. DefInt A-Z
  231.     '--- make the database handle a shared variable
  232.     Dim Handle
  233.     Dim RecData$
  234.     Dim RecNum&
  235. Sub Address_LostFocus ()
  236.     FldData$ = Address.Text
  237.     PutFLD Handle, Status, 4, FldName$, FldData$, RecData$
  238. End Sub
  239. Sub City_LostFocus ()
  240.     FldData$ = City.Text
  241.     PutFLD Handle, Status, 5, FldName$, FldData$, RecData$
  242. End Sub
  243. Sub ClearForm ()
  244.     '
  245.     'Clears out a form
  246.     '
  247.     FldData$ = ""
  248.     FName.Text = FldData$
  249.     LName.Text = FldData$
  250.     Contact.Text = FldData$
  251.     Address.Text = FldData$
  252.     City.Text = FldData$
  253.     State.Text = FldData$
  254.     Zip.Text = FldData$
  255.     HomePhone.Text = FldData$
  256.     WorkPhone.Text = FldData$
  257. End Sub
  258. Sub Contact_LostFocus ()
  259.     FldData$ = Contact.Text
  260.     PutFLD Handle, Status, 3, FldName$, FldData$, RecData$
  261. End Sub
  262. Sub DisplayRecord (RecNum&)
  263.     ThisRec.Text = LTrim$(Str$(RecNum&))
  264.     ReDim Flds$(0)
  265.     GetFLDS Handle, Status, NumFlds, Flds$(), RecNum&
  266.       If Status Then Exit Sub
  267.     FName.Text = Flds$(1)
  268.     LName.Text = Flds$(2)
  269.     Contact.Text = Flds$(3)
  270.     Address.Text = Flds$(4)
  271.     City.Text = Flds$(5)
  272.     State.Text = Flds$(6)
  273.     Zip.Text = Flds$(7)
  274.     HomePhone.Text = Flds$(8)
  275.     WorkPhone.Text = Flds$(9)
  276. End Sub
  277. Sub EndProgram ()
  278.     '
  279.     'Close database, unload server and exit program
  280.     '
  281.     CloseDBF Handle, Status, 0
  282.     Status = LogOffServer()
  283.     End
  284. End Sub
  285. Sub Fname_LostFocus ()
  286.     FldData$ = FName.Text
  287.     PutFLD Handle, Status, 1, FldName$, FldData$, RecData$
  288. End Sub
  289. Sub Form_Load ()
  290.     '
  291.     'Open the database if, if unsucessful then
  292.     'create it
  293.     '
  294.     '--- logon the server
  295.     Status = LogonServer()
  296.     If Not Status Then End
  297.     '--- open the database
  298.     Mode = 0
  299.     FileName$ = "ROLLODEX.DBF"
  300.     OpenDBF Handle, Status, FileName$, dbftype, Mode
  301.     '--- if can't open it, then create it
  302.     If Status Or (Handle = 0) Then
  303.         
  304.         ReDim Fld$(0 To 9, 0 To 5)
  305.         
  306.         Fld$(0, 0) = Str$(9)        'nine fields
  307.         
  308.         Fld$(1, 2) = Str$(15)       'length
  309.         Fld$(1, 3) = "C"            'character field
  310.         Fld$(1, 4) = "FIRSTNAME"    'field name
  311.         
  312.         Fld$(2, 2) = Str$(25)       'length
  313.         Fld$(2, 3) = "C"            'character field
  314.         Fld$(2, 4) = "LASTNAME"     'field name
  315.         
  316.         Fld$(3, 2) = Str$(8)        'length
  317.         Fld$(3, 3) = "D"            'character field
  318.         Fld$(3, 4) = "CONTACT"      'field name
  319.         Fld$(4, 2) = Str$(35)       'length
  320.         Fld$(4, 3) = "C"            'character field
  321.         Fld$(4, 4) = "ADDRESS"      'field name
  322.         
  323.         Fld$(5, 2) = Str$(15)       'length
  324.         Fld$(5, 3) = "C"            'character field
  325.         Fld$(5, 4) = "CITY"         'field name
  326.         Fld$(6, 2) = Str$(2)        'length
  327.         Fld$(6, 3) = "C"            'character field
  328.         Fld$(6, 4) = "STATE"        'field name
  329.         Fld$(7, 2) = Str$(5)        'length
  330.         Fld$(7, 3) = "N"            'character field
  331.         Fld$(7, 4) = "ZIP"          'field name
  332.         Fld$(8, 2) = Str$(14)       'length
  333.         Fld$(8, 3) = "C"            'character field
  334.         Fld$(8, 4) = "HOMEPHONE"    'field name
  335.         Fld$(9, 2) = Str$(14)       'length
  336.         Fld$(9, 3) = "C"            'character field
  337.         Fld$(9, 4) = "WORKPHONE"    'field name
  338.         Mode = 0
  339.         CreateDBF FileName$, Handle, Fld$(), Mode, Status
  340.         
  341.         '--- if any errors end program
  342.         If Status Then
  343.             MsgBox "Can't open rollodex", 48, "Error"
  344.             Unload RolloDex
  345.             End
  346.         End If
  347.         
  348.     End If
  349.     '--- get dbf's statistics
  350.     StatusDBF Handle, FileName$, ftype$, DBTPtr, NumRecs&, NumFlds, RecLen, UpDate$, Status
  351.     '--- fix up for scroll bar
  352.     If NumRecs& = 0 Then NumRecs& = 1
  353.     '--- assign min & max values to scroll bar
  354.     Record.Min = 1
  355.     Record.Max = NumRecs&
  356. End Sub
  357. Sub HomePhone_LostFocus ()
  358.     FldData$ = HomePhone.Text
  359.     PutFLD Handle, Status, 8, FldName$, FldData$, RecData$
  360. End Sub
  361. Sub Lname_LostFocus ()
  362.     FldData$ = LName.Text
  363.     PutFLD Handle, Status, 2, FldName$, FldData$, RecData$
  364. End Sub
  365. Sub New_Click ()
  366.         
  367.         '
  368.         'Makes a new record
  369.         '
  370.         RecNum& = 0
  371.         ClearForm
  372.         FName.SetFocus
  373. End Sub
  374. Sub Quit_Click ()
  375.     EndProgram
  376. End Sub
  377. Sub Record_Change ()
  378.     '
  379.     'Display the next record
  380.     '
  381.     RecNum& = Record.Value
  382.     DisplayRecord RecNum&
  383. End Sub
  384. Sub Save_Click ()
  385.     SaveForm
  386. End Sub
  387. Sub SaveForm ()
  388.     '
  389.     'Saves a database record to the database.
  390.     'Field data is saved as you tab between
  391.     'fields!
  392.     '
  393.     '--- save the record
  394.     OrigRec& = RecNum&
  395.     PutRec Handle, Status, RecNum&, RecData$
  396.     ThisRec.Text = LTrim$(Str$(RecNum&))
  397.     '--- get dbf's statistics
  398.     If OrigRec& <> RecNum& Then 'record added
  399.         Record.Min = 1
  400.         Record.Max = RecNum&
  401.         Record.Value = RecNum&
  402.     End If
  403. End Sub
  404. Sub State_LostFocus ()
  405.     FldData$ = State.Text
  406.     PutFLD Handle, Status, 6, FldName$, FldData$, RecData$
  407. End Sub
  408. Sub WorkPhone_LostFocus ()
  409.     FldData$ = WorkPhone.Text
  410.     PutFLD Handle, Status, 9, FldName$, FldData$, RecData$
  411. End Sub
  412. Sub Zip_LostFocus ()
  413.     FldData$ = Zip.Text
  414.     PutFLD Handle, Status, 7, FldName$, FldData$, RecData$
  415. End Sub
  416.